package com.sim.simserial.viewmodel

import android.content.Context
import android.util.Log
import androidx.lifecycle.viewModelScope
import com.drake.channel.sendEvent
import com.google.gson.Gson
import com.infinit.selfhelp.common.base.BaseViewModel
import com.infinit.selfhelp.common.ext.onDefaultThread
import com.infinit.selfhelp.common.ext.onIOThread
import com.sim.serialport.library.seria.DataStore
import com.sim.serialport.library.seria.SerialManager
import com.sim.serialport.library.seria.ext.formatString
import com.sim.simserial.R
import com.sim.simserial.ui.RequestAndResponseFragment.Companion.GET_LAST_APPROVED_TRANSACTION
import com.sim.simserial.ui.RequestAndResponseFragment.Companion.LOGON
import com.sim.simserial.ui.RequestAndResponseFragment.Companion.Request_terminal_status
import com.sim.simserial.ui.RequestAndResponseFragment.Companion.Settlement
import com.sim.simserial.ui.RequestAndResponseFragment.Companion.TMS
import com.sim.simserial.utils.SerialDataBuilder
import com.sim.storage.FunctionBean
import com.sim.storage.GoodList
import com.sim.storage.GoodsBean
import com.sim.storage.GoodsBeanParent
import com.sim.storage.GoodsCategoryData
import com.sim.storage.ResponseMessageBean
import com.sim.storage.enums.EXTRAEnum
import com.sim.storage.enums.ErrorReply
import com.sim.storage.enums.MILKTYPEEnum
import com.sim.storage.enums.SizeEnum
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.io.ByteArrayOutputStream
import java.io.IOException
import javax.inject.Inject

@HiltViewModel
class SimViewModel
@Inject
constructor(
    @ApplicationContext private val context: Context,
    val dataStore: DataStore,
    val gson: Gson,
    val serialManager: SerialManager
) : BaseViewModel() {
    companion object {
        const val ACK = "06"
        const val NACK = "15"
        const val STX = "02"
        const val APPROVED = "3030"
        const val REPLY_NACK_COUNT = 3
        const val NO_REPLY = "no_reply"
    }

    fun getData() {
        viewModelScope.launch {
            onDefaultThread {
                sendEvent(
                    FunctionEvent(
                        listOf(Settlement, TMS, GET_LAST_APPROVED_TRANSACTION).map { FunctionBean(it) }.toList(),
                    ),
                )
            }
        }
    }

    /**
     * @param buildString format is ********
     * */
    fun sendDataWithACK2(buildString: String) {
        serialManager.resetReceiveData()
        if (buildString.contains(" ") || buildString.length % 2 != 0) {
            throw Exception("format is error")
        }
        var analysisRequestData = SerialDataBuilder.analysisRequestData(formatString(buildString)) // 用来解析比对ECN
        val terminalReply = mutableListOf<String>()
        var trueReceiveData = mutableListOf<String>()

        val launch = viewModelScope.launch {
            onDefaultThread {
                serialManager.sendData(buildString)
                sendEvent(LogEvent(true, buildString))
            }
            var testIndex = 0
            onIOThread {
                var retryCount = 0  // pos resend 的次数上限是3,(算上第一次的发送[上面])
                var replyNACKCount = 0 // pos 回复 NACK的次数上限是3
                val maxRetries = 2
                val timeout = 2000L  // 2 seconds timeout
                var startTime = System.currentTimeMillis()

                while (isActive && (retryCount <= maxRetries || replyNACKCount <= REPLY_NACK_COUNT)) {
                    var receivedData = false
                    Log.d("receive--","$isActive $retryCount $replyNACKCount")
                    try {
                        var actualData = serialManager.onDataReceived


//                        // 这里埋入测试数据 开始 ------------------------------------------
////                         send data yong  02007730303030303030303537363833303031301C5432000230311C343000123030303030303030313030301C343200123030303030303030303030301C48440013313233343536373839303132331C031E
//                        analysisRequestData = SerialDataBuilder.analysisRequestData(formatString("02007730303030303030303537363833303031301C5432000230311C343000123030303030303030313030301C343200123030303030303030303030301C48440013313233343536373839303132331C031E"))
//                        testIndex++
//                        when (testIndex) {
//                            1 -> {
//                                actualData = ACK
//                            }
//
//                            2 -> {
//                                actualData =
//                                    "02 08 67 30 30 30 30 30 30 30 30 35 37 36 38 33 30 30 30 30 1C 30 32 00 40 41 50 50 52 4F 56 45 44 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 44 30 00 69 4E 45 54 53 20 54 65 73 74 20 4D 65 72 63 68 61 6E 74 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 30 33 00 06 31 38 31 32 30 31 1C 30 34 00 06 31 30 32 30 34 30 1C 31 36 00 08 31 30 30 35 30 32 30 32 1C 44 31 00 15 31 30 30 35 30 32 30 32 30 30 30 20 20 20 20 1C 36 35 00 06 30 30 30 34 35 36 1C 30 31 00 06 30 30 30 30 30 36 1C 44 33 00 12 31 32 33 34 35 36 31 32 33 34 35 36 1C 4C 37 00 20 54 45 53 54 20 43 41 52 44 20 20 20 20 20 20 20 20 20 20 20 1C 34 30 00 12 30 30 30 30 30 30 30 30 31 30 30 30 1C 34 31 00 12 30 30 30 30 30 30 30 30 30 30 32 30 1C 4C 35 02 40 50 4F 53 20 4D 65 73 73 61 67 65 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20"
//                            }
//                            3->{
//                                actualData = "20 20 20 1C 52 30 00 20 52 65 73 70 6F 6E 73 65 20 4D 65 73 73 61 67 65 20 49 20 20 1C"
//                            }
//                            4->{
//                                actualData = "52 31 00 20 52 65 73 70 6F 6E 73 65 20 4D 65 73 73 61 67 65 20 49 49 20 1C 4C 31 00 24 4C 6F 79 61 6C 74 79 20 50 72 6F 6D 6F 74 69 6F 6E 20 20 20 20 20 20 20 1C 4C 38 00 08 32 31 31 32 32 30 31 34 1C 4C 32 00 01 32 1C 4C 39 01 44 4C 6F 79 61 6C 74 79 20 4D 65 73 73 61 67 65 20 31 34 34 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 4C 33 00 12 30 30 30 30 30 30 30 30 32 30 30 30 1C 4C 34 00 12 30 30 30 30 30 30 30 30 35 30 30 30 1C 48 43 00 02 30 30 1C 43 4E 00 02 31 30 1C 52 50 00 21 4D 79 20 52 65 63 65 69 70 74 20 50 72 69 6E 74 20 64 61 74 61 1C 59 59 00 06 58 58 58 58 58 58 1C 03 77"
//                            }

                            //Test_12 Test_13
//                            1 -> {
//                            }
//                            2->{
//                                actualData = NACK
//                            }
//                            3,4 -> {
//                                actualData =
//                                    "02 05 46 35 33 36 34 39 37 38 33 31 30 30 39 49 30 30 31 30 1C 30 32 00 40 41 50 50 52 4F 56 45 44 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 44 30 00 69 4E 45 54 53 20 54 65 73 74 20 4D 65 72 63 68 61 6E 74 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 30 33 00 06 31 38 31 32 30 31 1C 30 34 00 06 31 30 32 30 34 30 1C 30 31 00 06 30 30 30 30 30 36 1C 39 48 00 06 31 32 33 34 35 36 1C 31 36 00 08 31 30 30 35 30 32 30 32 1C 44 31 00 15 31 30 30 35 30 32 30 32 30 30 30 20 20 20 20 1C 44 32 00 10 44 42 53 20 42 61 6E 6B 20 20 1C 39 4D 00 10 4D 41 53 54 45 52 43 41 52 44 1C 33 30 00 16 31 31 31 31 37 33 37 39 31 30 30 31 31 32 30 35 1C 44 37 00 03 44 42 53 1C 44 38 00 06 4D 79 43 61 72 64 1C 33 31 00 04 30 30 30 30 1C 35 30 00 06 30 30 30 30 30 30 1C 44 33 00 12 31 32 33 34 35 36 31 32 33 34 35 36 1C 44 36 00 26 54 6F 6E 79 20 50 68 65 6E 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 39 41 00 16 41 30 30 30 31 30 30 30 30 30 30 31 30 30 30 30 1C 39 42 00 16 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38 1C 39 43 00 02 31 32 1C 39 44 00 16 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38 1C 39 46 00 04 31 32 33 34 1C 39 45 00 11 31 32 33 34 35 31 32 33 34 35 36 1C 41 31 00 10 31 32 33 34 35 36 37 38 39 30 1C 39 49 00 08 38 30 30 30 30 30 30 30 1C 48 43 00 02 30 30 1C 43 4E 00 02 31 30 1C 39 33 00 02 30 31 1C 39 34 00 19 4C 6F 79 61 6C 74 79 20 49 6E 66 6F 72 6D 61 74 69 6F 6E 1C 52 50 00 21 4D 79 20 52 65 63 65 69 70 74 20 50 72 69 6E 74 20 64 61 74 61 1C 03 3A"
//                            }
//                            5->{
//                                actualData =
//                                    "02 05 46 35 33 36 34 39 37 38 33 31 30 30 39 49 30 30 31 30 1C 30 32 00 40 41 50 50 52 4F 56 45 44 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 44 30 00 69 4E 45 54 53 20 54 65 73 74 20 4D 65 72 63 68 61 6E 74 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 30 33 00 06 31 38 31 32 30 31 1C 30 34 00 06 31 30 32 30 34 30 1C 30 31 00 06 30 30 30 30 30 36 1C 39 48 00 06 31 32 33 34 35 36 1C 31 36 00 08 31 30 30 35 30 32 30 32 1C 44 31 00 15 31 30 30 35 30 32 30 32 30 30 30 20 20 20 20 1C 44 32 00 10 44 42 53 20 42 61 6E 6B 20 20 1C 39 4D 00 10 4D 41 53 54 45 52 43 41 52 44 1C 33 30 00 16 31 31 31 31 37 33 37 39 31 30 30 31 31 32 30 35 1C 44 37 00 03 44 42 53 1C 44 38 00 06 4D 79 43 61 72 64 1C 33 31 00 04 30 30 30 30 1C 35 30 00 06 30 30 30 30 30 30 1C 44 33 00 12 31 32 33 34 35 36 31 32 33 34 35 36 1C 44 36 00 26 54 6F 6E 79 20 50 68 65 6E 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1C 39 41 00 16 41 30 30 30 31 30 30 30 30 30 30 31 30 30 30 30 1C 39 42 00 16 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38 1C 39 43 00 02 31 32 1C 39 44 00 16 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38 1C 39 46 00 04 31 32 33 34 1C 39 45 00 11 31 32 33 34 35 31 32 33 34 35 36 1C 41 31 00 10 31 32 33 34 35 36 37 38 39 30 1C 39 49 00 08 38 30 30 30 30 30 30 30 1C 48 43 00 02 30 30 1C 43 4E 00 02 31 30 1C 39 33 00 02 30 31 1C 39 34 00 19 4C 6F 79 61 6C 74 79 20 49 6E 66 6F 72 6D 61 74 69 6F 6E 1C 52 50 00 21 4D 79 20 52 65 63 65 69 70 74 20 50 72 69 6E 74 20 64 61 74 61 1C 03 39"
//
//                            }
//                        }
//                        // 这里埋入测试数据 结束 ------------------------------------------


                        if (actualData.isNotEmpty()) {
                            if (!actualData.contains(" ")) {
                                actualData = formatString(actualData)
                            }

                            receivedData = true
                            sendEvent(LogEvent(false, actualData))

                            if (actualData == NACK || actualData == ACK) {
                                terminalReply.add(actualData)
                            }
                            if (actualData == NACK) {
                                retryCount++
                                if (retryCount <= maxRetries) {
                                    serialManager.sendData(buildString)
                                    startTime = System.currentTimeMillis()
                                    sendEvent(LogEvent(true, buildString))
                                } else {
                                    sendErrorEvent(terminalReply)
                                    return@onIOThread
                                }
                            } else if (actualData == ACK) {
                                continue
                            } else {
                                // 检查LRC前，要判断完整性，以此来判断是不是分段的
                                trueReceiveData.addAll(actualData.split(" "))
                                val length = "${trueReceiveData[1]}${trueReceiveData[2]}"
                                // 10 是 STX + LEN(2) + ETX + LRC 的长度
                                if (length.toInt() + 5 != trueReceiveData.size) {
                                    // 说明是分割数据， 需要等待
                                    continue
                                } else {
                                    actualData = trueReceiveData.joinToString(" ")
                                }


                                // check LRC
                                if (actualData.startsWith(STX)) {
                                    // 02 开头，说明是valid data
                                    if (SerialDataBuilder.checkLRC(actualData)) {
                                        // 如果是有效的 LRC ，则分析数据。解析正确就可以 send ACK
                                        SerialDataBuilder.analysisReceiveData(actualData)?.let {
                                            if (analysisRequestData?.messageHeader?.ecn == it.messageHeader.ecn) {
                                                // 有效的返回数据
                                                serialManager.sendData(ACK)
                                                sendEvent(LogEvent(true, ACK))
                                                sendEvent(ResponseEvent(it))
                                                if (it.messageHeader.responseCode == APPROVED) {
                                                    // approved transaction
                                                    sendEvent(WrongLRCEvent("APPROVED transaction"))
                                                } else {
                                                    sendEvent(WrongLRCEvent("DECLINED transaction"))
                                                }
                                                return@onIOThread
                                            } else {
                                                sendEvent(WrongLRCEvent("wrong ECN")) // TODO  ECN 不一样的情况， 要确定
                                                return@onIOThread
                                            }
                                        }
                                    } else {
                                        // invalid LRC,
                                        replyNACKCount++
                                        if (replyNACKCount <= REPLY_NACK_COUNT) {
                                            serialManager.sendData(NACK)
                                            sendEvent(LogEvent(true, NACK))
                                        }
                                        if (replyNACKCount == REPLY_NACK_COUNT) {
                                            // 收到3次 wrong LRC ， POS should prompted for APPROVED/FLAGGED the transaction
                                            SerialDataBuilder.analysisReceiveData(actualData)?.let {
                                                if (it.messageHeader.responseCode == APPROVED) {
                                                    // approved transaction
                                                    sendEvent(WrongLRCEvent("prompted for APPROVED/FLAGGED the transaction"))
                                                } else {
                                                    sendEvent(WrongLRCEvent("prompted for DECLINED/FLAGGED the transaction"))
                                                }
                                            }
                                            return@onIOThread
                                        }
                                    }
                                }
                            }
                        }
                    } catch (e: IOException) {
                        e.printStackTrace()
                    }

                    if (terminalReply.lastOrNull() == ACK) {
                        delay(100)
                        continue
                    } else {
                        if (!receivedData && System.currentTimeMillis() - startTime >= timeout) {
                            retryCount++
                            if (retryCount <= maxRetries) {
                                serialManager.sendData(buildString)
                                terminalReply.add(NO_REPLY)
                                sendEvent(LogEvent(true, buildString))
                                startTime = System.currentTimeMillis()
                            } else {
                                sendErrorEvent(terminalReply)
                                break
                            }
                        }
                    }
                    delay(100)
                }
            }
        }
        serialManager.addReceiveJob(launch)
    }

    private fun sendErrorEvent(terminalReply: MutableList<String>) {
        if (terminalReply.last() == NO_REPLY) {
            // terminal no reply
            sendEvent(ErrorReplyEvent(ErrorReply.Error_Last_No_Reply))
        } else if (terminalReply.filter { it == NACK }.size == 3) {
            sendEvent(ErrorReplyEvent(ErrorReply.Error_NACK))
        } else {
            sendEvent(ErrorReplyEvent(ErrorReply.Error_NoReply_NACK))
        }
    }

    fun getGoodsCategory() {
        viewModelScope.launch {
            onDefaultThread {
                val listOf = listOf(
                    GoodsCategoryData("Cappuccino", true),
                    GoodsCategoryData("Latte", false),
                    GoodsCategoryData("Americano", false),
                    GoodsCategoryData("Expresso", false),
                    GoodsCategoryData("Flat White", false)
                )
                sendEvent(GoodsCategoryEvent(listOf))
            }
        }
    }

    fun getGoodsList() {
        viewModelScope.launch {
            onDefaultThread {
                val goodsBeanParent = GoodsBeanParent(
                    listOf(
                        GoodList(
                            "Cappuccino", listOf(
                                GoodsBean("Cappuccino1", R.mipmap.cappuccino, 0.1f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Cappuccino2", R.mipmap.cappuccino, 0.2f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Cappuccino3", R.mipmap.cappuccino, 0.3f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Cappuccino4", R.mipmap.cappuccino, 0.4f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Cappuccino5", R.mipmap.cappuccino, 0.5f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK)
                            )
                        ),
                        GoodList(
                            "Latte", listOf(
                                GoodsBean("Latte1", R.mipmap.cappuccino, 0.1f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Latte2", R.mipmap.cappuccino, 1f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Latte3", R.mipmap.cappuccino, 13f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Latte4", R.mipmap.cappuccino, 14f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Latte5", R.mipmap.cappuccino, 15f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK)
                            )
                        ),
                        GoodList(
                            "Americano", listOf(
                                GoodsBean("Americano 1", R.mipmap.cappuccino, 0.1f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Americano 2", R.mipmap.cappuccino, 1f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Americano 3", R.mipmap.cappuccino, 13f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Americano 4", R.mipmap.cappuccino, 14f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Americano 5", R.mipmap.cappuccino, 15f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK)
                            )
                        ),
                        GoodList(
                            "Expresso", listOf(
                                GoodsBean("Expresso 1", R.mipmap.cappuccino, 0.1f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Expresso 2", R.mipmap.cappuccino, 1f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Expresso 3", R.mipmap.cappuccino, 13f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Expresso 4", R.mipmap.cappuccino, 14f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Expresso 5", R.mipmap.cappuccino, 15f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK)
                            )
                        ),
                        GoodList(
                            "Flat White", listOf(
                                GoodsBean("Flat White 1", R.mipmap.cappuccino, 21f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Flat White 2", R.mipmap.cappuccino, 22f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Flat White 3", R.mipmap.cappuccino, 23f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Flat White 4", R.mipmap.cappuccino, 24f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK),
                                GoodsBean("Flat White 5", R.mipmap.cappuccino, 25f, false, 0, SizeEnum.SHORT, EXTRAEnum.SUGAR, MILKTYPEEnum.OAT_MILK)
                            )
                        )
                    )
                )
                sendEvent(GoodsListEvent(goodsBeanParent))
            }
        }
    }


    open class XSimEvent

    data class LogEvent(val isPos: Boolean, val log: String) : XSimEvent()
    data class ResponseEvent(val response: ResponseMessageBean) : XSimEvent()
    data class ErrorReplyEvent(val error: ErrorReply) : XSimEvent()
    data class WrongLRCEvent(val error: String) : XSimEvent()


    data class GoodsListEvent(val goods: GoodsBeanParent)
    data class FunctionEvent(val list: List<FunctionBean>)
    data class GoodsCategoryEvent(val list: List<GoodsCategoryData>)

}
